package com.dongdongshop.controller;

import com.dongdongshop.enums.ResultEnum;
import com.dongdongshop.page.PageBean;
import com.dongdongshop.service.GoodsService;
import com.dongdongshop.util.Result;
import com.dongdongshop.vo.GoodsVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("goods")
public class GoodsController {
    @DubboReference
    private GoodsService gs;


    @RequestMapping("show")
    public String show(){
        return "admin/goods";
    }

    @RequestMapping("getAll")
    @ResponseBody
    public Result getAll(String goodsName){
        try {
            List<GoodsVO> all = gs.getAll(goodsName);
            return Result.OK().setData(all);
        } catch (Exception e) {
            return Result.ERROR();
        }
    }

    @RequestMapping("updateUp")
    @ResponseBody
    public Result updateUp(String auditStatus,String[] ids){
        try {
            gs.update(auditStatus,ids);
            return Result.OK();
        } catch (Exception e) {
            return Result.response(ResultEnum.UPDATE_MESSAGE_ERROE);
        }

    }


    @RequestMapping("deleteCheck")
    @ResponseBody
    public Result deleteCheck(Long[] ids){
        try {
            gs.deleteCheck(ids);
            return Result.OK();
        } catch (Exception e) {
            return Result.response(ResultEnum.DELETE_MESSAGE_ERROE);
        }
    }
}
